package com.eshin.demo.custom;

import static ch.qos.logback.core.util.OptionHelper.extractDefaultReplacement;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import ch.qos.logback.classic.pattern.ClassicConverter;
import ch.qos.logback.classic.spi.ILoggingEvent;

public class CustomConverter extends ClassicConverter {

	/*static {
		PatternLayout.defaultConverterMap.put("custom", CustomConverter.class.getName());
	}*/
	private String key;
    private String defaultValue = "";
    public static final Map<String,String>keywordsMap = new HashMap<String, String>();
	static {
    	System.out.println("classLoader in static:"+ CustomConverter.class.getClassLoader());
    	keywordsMap.put("test", "hellotest");
    }
	@Override
    public void start() {
        String[] keyInfo = extractDefaultReplacement(getFirstOption());
        key = keyInfo[0];
        if (keyInfo[1] != null) {
            defaultValue = keyInfo[1];
        }
        super.start();
    }
	@Override
	public String convert(ILoggingEvent event) {
//		System.out.println(keywordsMap +" :" + keywordsMap.size());
		String value = CustomConverter.keywordsMap.get(key.trim());
//		System.out.println("classLoader in CustomConverter:"+this.getClass().getClassLoader());
//		getKeywordsMap();
		return value ;
	}
	public static Map<String, String> getKeywordsMap() {
//		System.out.println("classLoader in getKeywordsMap:"+CustomConverter.class.getClassLoader());
//		System.out.println(keywordsMap +" in static method:" + keywordsMap.size());
		return keywordsMap;
	}
	
}
